package com.voice.call.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.voice.call.entity.InviteLog;
import com.voice.call.mapper.InviteLogMapper;
import com.voice.call.service.InviteLogService;

@Service
public class InviteLogServiceImpl implements InviteLogService{
	
	@Resource
	private InviteLogMapper inviteLogMapper;

	//判断是否已被邀请过
	@Override
	public	boolean existsInvite(Integer user_id){
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("inviteUserId", user_id);
		int total = inviteLogMapper.count(paramsMap);
		if(total >0){
			return true;
		}
		return false;
	}
	
	@Override
	public boolean addInviteLog(Integer user_id,Integer inviteUserId,Integer inviteId){
		InviteLog entity = new InviteLog();
		entity.setUserId(user_id);
		entity.setInviteUserId(inviteUserId);
		entity.setInviteId(inviteId);
		entity.setCtime(new Date());
		return inviteLogMapper.insert(entity)>0?true:false;
	}
	//获取上层邀请人
	@Override
	public	InviteLog getUpperInviteUser(Integer user_id){
		//取得上级邀请人
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("inviteUserId", user_id);
		List<InviteLog> list = inviteLogMapper.list(paramsMap);
		if(list!=null && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}
	
	//获取某个人的邀请数
	@Override
	public	int inviteCount(Integer user_id){
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("userId", user_id);
		return inviteLogMapper.inviteCount(paramsMap);
	}
}
